/* httpDemo.java 
* Created on Dec 13, 2012 
*@Author: Mr.Viet 
*@Phone: 01683430426 
*@Email: phamvanvietcdhd@gmail.com
*/ 
package com.seo; 

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

public class URLRequest {
	
	public URLRequest() {
	}

	public static void main(String[] args) {
		try {
			URL url = new URL("http://localhost/doApp.php");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("POST");
			conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			conn.setRequestProperty("charset", "UTF-8");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			String Data = "user=phamvanviet&pass=123 ";
			conn.setRequestProperty("Content-Length", Data.length()+"");
			conn.connect();
			//Gui Data Di
			OutputStream out = conn.getOutputStream();
			out.write(Data.getBytes());
			out.flush();
			out.close();
			//Nhan Du Lieu Ve
			InputStream in = conn.getInputStream();
			byte[] b = new byte[in.available()];
			in.read(b);
			System.out.println(new String(b));
			in.close();
			//Dong Dong Ket Noi
			conn.disconnect();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
